package com.cqie.secondhandtransaction.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

import com.cqie.secondhandtransaction.DTO.ChatInfoDTO;
import com.cqie.secondhandtransaction.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * <p>
 * 
 * </p>
 *
 * @author gdy
 * @since 2025-02-10
 */
@Getter
@Setter
@TableName("chat_info")
@ApiModel(value = "ChatInfo对象", description = "")
public class ChatInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("买家id")
    private Integer userId;

    @ApiModelProperty("买家id")
    private Integer sallerId;

    @ApiModelProperty("聊天室编号，确保用户和商家的聊天室唯一")
    private String chatCode;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date createTime;

    @ApiModelProperty("聊天内容")
    private String content;

    @ApiModelProperty("发送者类型：USER-用户, SELLER-商家")
    private String senderType;

    public ChatInfoDTO toChatInfoDTO(){
        ChatInfoDTO chatInfoDTO = new ChatInfoDTO();
        chatInfoDTO.setId(this.id);
        chatInfoDTO.setCreateTime(this.createTime);
        chatInfoDTO.setContent(this.content);
        chatInfoDTO.setSenderType(this.senderType);
        chatInfoDTO.setChatCode(this.chatCode);
        return chatInfoDTO;
    }

}
